<template>
  <div>
    <div style='margin:50px 0 0 50px'>
        <el-switch
            v-model="info"
            active-text="客户信息"
            inactive-text="标签信息">
        </el-switch>
    </div>
    <el-table
      :data="order_list"
      :row-key="getRowKeys"
      :expand-row-keys="expands"
      @expand-change='expand'
      style="width: 100%">
      <el-table-column 
        type="expand"
      >
        <template slot-scope="scope">
            <div v-for="t in scope.row.type" style='float:left; margin:30px' :key='t.id'>
            <el-card class="box-card" style='width:400px;'>
            <div slot="header" class="clearfix">
                <span>{{ t.type }}</span>
                <!-- <el-button style="float: right; padding: 3px 0" type="text">操作按钮</el-button> -->
            </div>
            <el-form>
                <el-form-item label='描述'>
                    {{ t.desc }}
                </el-form-item>
                <el-form-item label='启动延时'>
                    {{ t.delay }}
                </el-form-item>
                <el-form-item label='计时周期'>
                    {{ t.period + " 分钟" }}
                </el-form-item>
                <el-form-item label='温度区间'>
                    {{ t.low_temp + "℃ ~ " + t.high_temp + '℃' }}
                </el-form-item>
                <el-form-item label='公司'>
                    {{ t.office.office }}
                </el-form-item>
            </el-form>
            </el-card>
            </div>
        </template>
      </el-table-column>
      <el-table-column
        label="订单号"
        prop="order"
        :width="320"
        >
      </el-table-column>
      <el-table-column
        label="温度区间" v-if="!info" :width="150">
        <template slot-scope="scope">
          {{ scope.row.low_temp + "℃ ~ " + scope.row.high_temp + "℃" }}
        </template>
      </el-table-column>
      <el-table-column label='记录间隔' v-if="!info" :width="100">
        <template slot-scope="scope">
          {{ scope.row.type[0].period }}
        </template>
      </el-table-column>
      <el-table-column label='启动延时' v-if="!info" :width="100">
        <template slot-scope="scope">
          {{ delay_max(scope.row.type) }}
        </template>
      </el-table-column>
      <el-table-column label='设备' v-if="!info" :width="100">
        <template slot-scope="scope">
          {{ scope.row.equipment.equipment }}
        </template>
      </el-table-column>
      
      <el-table-column label='状态' v-if="!info" :width="100">
        <template slot-scope="scope">
          {{ scope.row.result }}
        </template>
      </el-table-column>
      <el-table-column label='开始时间' v-if="!info">
        <template slot-scope="scope">
          {{ scope.row.start_time | time_form }}
        </template>
      </el-table-column>
      <el-table-column label='结束时间' v-if="!info">
        <template slot-scope="scope">
          {{ scope.row.end_time | time_form }}
        </template>
      </el-table-column>
      <el-table-column label='创建时间' v-if="!info">
        <template slot-scope="scope">
          {{ scope.row.create_time | time_form }}
        </template>
      </el-table-column>
      <el-table-column label='查看校验报告' v-if="!info">
        <template slot-scope="scope">
            <a href="javascript:void(0);" @click='show_log(scope.row.report)'>查看校验报告</a>
        </template>
      </el-table-column>
      
      <el-table-column label='客户公司' v-if="info">
        <template slot-scope="scope">
          {{ scope.row.custom.custom }}
        </template>
      </el-table-column>
      <el-table-column label='客户地址' v-if="info">
        <template slot-scope="scope">
          {{ scope.row.custom.address }}
        </template>
      </el-table-column>
      <el-table-column label='客户电话1' v-if="info">
        <template slot-scope="scope">
          {{ scope.row.custom.phone }}
        </template>
      </el-table-column>
      <el-table-column label='客户电话2' v-if="info">
        <template slot-scope="scope">
          {{ scope.row.custom.phone2 }}
        </template>
      </el-table-column>
      <el-table-column label='客户姓名' v-if="info">
        <template slot-scope="scope">
          {{ scope.row.custom.name }}
        </template>
      </el-table-column>
      
      <el-table-column label='发件公司' v-if="info">
        <template slot-scope="scope">
          {{ scope.row.type[0].office.office }}
        </template>
      </el-table-column>
      <el-table-column label='发件地址' v-if="info">
        <template slot-scope="scope">
            <a href="javascript:void(0);" @click='show_address(scope.row.origin)'>查看</a>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="收货地址" :visible.sync="log_show">
    <el-table
        :data="log_list"
        height="500"
        border
        style="width: 100%">
        <el-table-column
            prop="time"
            label="时间"
            width="180">
        </el-table-column>
        <el-table-column
            prop="temp"
            label="温度"
            width="180">
        </el-table-column>
        <el-table-column
            prop="judge"
            label="报告">
        </el-table-column>
        <el-table-column
            prop="lon"
            label="经度">
        </el-table-column>
        <el-table-column
            prop="lat"
            label="纬度">
        </el-table-column>
    </el-table>
    </el-dialog>
    
    <el-dialog
    title="发件地址"
    :visible.sync="origin_dialog"
    width="30%"
    >
    <span>{{ origin_info }}</span>
    <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
    </span>
    </el-dialog>
    <!-- <el-dialog title="输入角色信息" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="角色名" :label-width="formLabelWidth">
          <el-input v-model="form.character" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="公司" :label-width="formLabelWidth">
          <el-select v-model="form.office_id" placeholder="请选择">
            <el-option
              v-for="item in office_list"
              :key="item.id"
              :label="item.office"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit_add">确 定</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<style>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>

<script>
import {
  right_get,
  character_get,
  character_post,
  character_right_get,
  character_right_post,
  office_get,
  order_get
} from "../axios_api/api";
export default {
  data() {
    return {
      log_show:false,
      log_list: [],
      origin_dialog: false,
      origin_info: "",
      info: false,
      order_list: [],
      formLabelWidth: "120px",
      form: {
        character: "",
        office_id: 0
      },
      office_list: [],
      getRowKeys(row) {
        return row.id;
      },
      expands: [10],
      data: [],
      value: [],
      filterMethod(query, item) {
        return item.label.indexOf(query) > -1;
      },
      tableData: []
    };
  },
  mounted() {
    // this.get_charcters();
    // this.get_rights();
    // this.get_office();
    this.get_orders();
  },
  methods: {
    show_log(log_li){
        this.log_show = true
        this.log_list = JSON.parse(log_li).log
    },
    show_address(origin) {
      this.origin_dialog = true;
      if (!origin) {
        this.origin_info = "暂无";
      } else {
        this.origin_info = origin;
      }
    },
    delay_max(type) {
      var delay = 0;
      for (var i = 0; i < type.length; i++) {
        if (type[i].delay > delay) {
          delay = type[i].delay;
        }
      }
      return delay;
    },
    get_orders() {
      order_get().then(resp => {
        this.order_list = resp.data;
      });
    },
    // submit_add() {
    //   console.log(this.form);
    //   character_post(this.form).then(resp => {
    //     this.$message(resp.message);
    //     if (resp.data == 200) {
    //       this.$router.go(0);
    //     }
    //   });
    // },
    // 获取公司列表
    get_office() {
      office_get().then(resp => {
        this.office_list = resp.data;
      });
    },
    // 展开单元行
    expand(row, expandedRows) {
      this.child_loading = true;
      var that = this;
      if (expandedRows.length) {
        that.expands = [];
        if (row) {
          that.expands.push(row.id);
        }
      } else {
        that.expands = [];
      }
      // 请求详细数据
      // character_right_get({ character_id: row.id }).then(resp => {
      //   console.log(resp.data);
      //   this.value = [];
      //   for (var i = 0; i < resp.data.length; i++) {
      //     this.value.push(resp.data[i].id);
      //   }
      //   console.log(this.value);
      // });
    },
    // 提交修改
    submit(id) {
      var data = { character_id: id, right_id_list: this.value };
      character_right_post(data).then(resp => {
        this.$message(resp.message);
        if (resp.code == 200) {
          this.$router.go(0);
        }
      });
    },
    //分情况渲染公司名
    office_name(office) {
      if (office) {
        return office.office;
      } else {
        return "全局";
      }
    },
    // 获取权限列表
    get_rights() {
      right_get().then(resp => {
        console.log(resp);
        for (let i = 0; i < resp.data.length; i++) {
          let data = resp.data[i];
          let item = {};
          item["disabled"] = false;
          item["key"] = data.id;
          item["label"] = data.desc;
          this.data.push(item);
        }
      });
    },
    // 获取角色列表
    get_charcters() {
      character_get().then(resp => {
        this.tableData = resp.data;
      });
    }
  },
  filters: {
    time_form(value) {
      if (!value) {
        return "--";
      }
      return value
        .split("T")
        .join(" ")
        .split(".")[0];
    }
  }
};
</script>
<style>
</style>

